import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import { systemid } from '../../atom/config';

interface Message {
	filter: {
		cust_name: string;
		contact_address: string;
		memo: string;
		industry_domain_no: string;
		industry_domain_name: string;
	}
}


// 表名	pub_client
// 标题	企业客户
// 字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
// _id	id	string	50	ⅹ	√
// client_no	客户编号	string	50	ⅹ	ⅹ
// cust_name	客户名称	string	50	ⅹ	ⅹ
// contact_address	联系地址	string	50	√	ⅹ
// memo	备注	string	500	√	ⅹ
// industry_domain_no	行业领域编号	string	50	√	ⅹ
// industry_domain_name	行业领域名称	string	50	√	ⅹ


export default async function atom(msg: Message, action_id: string, session_id: string) {
	log('Service begin');
	console.log('-----------------------------------');
	// todo
	const { insert, exec } = operate(action_id, session_id, systemid);

	const { result } = await doc_code(action_id, session_id, systemid, 'BM0012818', '', 1);
	insert('pub_client', { client_no: result, cust_name: msg.filter.cust_name, contact_address: msg.filter.contact_address, memo: msg.filter.memo, industry_domain_no: msg.filter.industry_domain_no, industry_domain_name: msg.filter.industry_domain_name });
	const res = await exec();
	log('Service end');
	return res;
}
